package com.example.demo2.student;


import com.example.demo2.Util.DBHelper;
import com.example.demo2.pojo.student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
/**
 * <p>
 *
 * </p>
 * @author rzw
 * @date 2023/12/14
 * @Version: 1.0
 *
 */
@WebServlet("/DelClasss")
public class DelClasss extends HttpServlet {
	private static final long serialVersionUID = 1L;



	public DelClasss() {
		super();

	}

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		Connection conn = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		int id =Integer.parseInt(request.getParameter("id"));
		com.example.demo2.Util.DBHelper dBHelper = new DBHelper();
		 conn = dBHelper.getConn();
		try {
			preparedStatement = conn.prepareStatement("delete  from webdesign.class where id =?");
			preparedStatement.setInt(1,id);
			int i = preparedStatement.executeUpdate();
		} catch (SQLException e) {
			throw new RuntimeException(e);
		} finally {
			dBHelper.closeAll(conn, preparedStatement, resultSet);
		}
		request.getRequestDispatcher("/classslist.jsp").forward(request, response);
	}

}
